package com.gitee.aurora.controller;


import com.gitee.aurora.entity.PtConfig;
import com.gitee.aurora.entity.PtcjConfig;
import com.gitee.aurora.entity.SqlConfigItem;
import com.gitee.aurora.entity.TableConfig;
import com.gitee.aurora.service.PtConfigService;
import com.gitee.aurora.utils.PageParam;
import com.gitee.aurora.utils.Pagination;
import com.gitee.aurora.utils.ResultVO;
import com.gitee.aurora.utils.ResultVOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/ptConfig")
public class PtConfigController {
    @Autowired
    private PtConfigService ptConfigService;

    //获取检测机构树
    @GetMapping("/ptTree")
    @ResponseBody
    public ResultVO<List<PtcjConfig>> ptTree()  {
        List<PtcjConfig> treeList= null;
        try {
            treeList = ptConfigService.queryPtcjConfig();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultVOUtils.success(treeList);
    }
   //查询检测机构配置
    @PostMapping("/queryPtConfig")
    @ResponseBody
    public ResultVO<Pagination> queryPtConfig(PtConfig ptConfig, PageParam pageParam) {
        Pagination pagination= null;
        try {
            pagination = ptConfigService.queryPtConfigService(ptConfig,pageParam);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  ResultVOUtils.success(pagination);
    }

    //查询检测数据表下拉列表
    @GetMapping("/queryPtTableConfig")
    @ResponseBody
    public ResultVO<List<TableConfig>> queryPtTableConfig()  {
        List<TableConfig> pList= null;
        try {
            pList = ptConfigService.queryTable();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  ResultVOUtils.success(pList);
    }

    //查询平台类型
    @GetMapping("/queryPtLx")
    @ResponseBody
    public ResultVO<List<SqlConfigItem>> queryPtLx() {
        List<SqlConfigItem> pList= null;
        try {
            pList = ptConfigService.queryPtLx();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  ResultVOUtils.success(pList);
    }

    //查询平台系列
    @GetMapping("/queryPtXl")
    @ResponseBody
    public ResultVO<List<SqlConfigItem>> queryPtXl() {
        List<SqlConfigItem> pList= null;
        try {
            pList = ptConfigService.queryPtXl();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  ResultVOUtils.success(pList);
    }
    //删除平台配置数据
    @PostMapping("/deletePtConfig")
    @ResponseBody
    public ResultVO deletePtConfig(PtConfig ptConfig) {
        int result=0;
        try {
              result=ptConfigService.deletePtConfigService(ptConfig);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  ResultVOUtils.success(result);
    }
    //修改平台配置数据
    @PostMapping("/updatePtConfig")
    @ResponseBody
    public ResultVO updatePtConfig(PtConfig ptConfig) {
        /* List<SqlConfigItem> pList= null;*/
        int result=0;
        try {
            result= ptConfigService.updatePtConfigService(ptConfig);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  ResultVOUtils.success(result);
    }
    //新增平台配置数据
    @PostMapping("/insertPtConfig")
    @ResponseBody
    public ResultVO insertPtConfig(PtConfig ptConfig) {
        /* List<SqlConfigItem> pList= null;*/
        int result=0;
        try {
            result= ptConfigService.insertPtConfigService(ptConfig);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  ResultVOUtils.success(result);
    }


}
